package com.bwie.parkdemo.widget;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import com.bwie.parkdemo.R;
import com.chad.library.adapter.base.BaseQuickAdapter;

/**
 * 未分组部门fragment中弹出的popupwindow用来显示全部部门
 *
 * * */
public class DepartmentPop {

    private PopupWindow popupWindow;
    private View rootView;
    private RecyclerView rv;
    private Context ctx;

    public DepartmentPop(Context ctx){
        this.ctx = ctx;
        init();
    }

    private void init(){
        rootView = LayoutInflater.from(ctx)
                .inflate(R.layout.pop_department,null);
        rv = rootView.findViewById(R.id.department_pop_rv);
        popupWindow = new PopupWindow(rootView, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT,false);
        popupWindow.setOutsideTouchable(false);
        GridLayoutManager manager = new GridLayoutManager(ctx,3);
        manager.setOrientation(GridLayoutManager.VERTICAL);
        rv.setLayoutManager(manager);
    }

    public void setAdapter(BaseQuickAdapter adapter){
        rv.setAdapter(adapter);
    }

    public void show(View view){
        if (popupWindow == null)
            return;
        popupWindow.showAtLocation(view, Gravity.BOTTOM,0,0);
    }

    public void disPop(){
        if (popupWindow != null){
            if (popupWindow.isShowing())
                popupWindow.dismiss();
        }
    }

}
